
import { createApp } from 'vue'

import Cookies from 'js-cookie'

import App from './App.vue'

import Antd from 'ant-design-vue';
import Storage from 'vue-ls'
import constantRoutes from './router/index'
import {hiPrintPlugin} from 'vue-plugin-hiprint'
import ElementPlus from 'element-plus'
import store from './store'
import 'element-plus/theme-chalk/index.css'
import * as Icons from '@element-plus/icons-vue'; 
import print from 'vue3-print-nb'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import { Document, Menu as IconMenu, Setting, User, UserFilled, CreditCard, Printer, Box, ShoppingTrolley, Timer } from "@element-plus/icons-vue"

// 解决ResizeObserver loop bug
const debounce = (fn, delay) => {
    let timer = null;
    return function () {
      let context = this;
      let args = arguments;
      clearTimeout(timer);
      timer = setTimeout(function () {
        fn.apply(context, args);
      }, delay);
    }
  }
  
  const _ResizeObserver = window.ResizeObserver;
  window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
    constructor(callback) {
      callback = debounce(callback, 16);
      super(callback);
    }
  }
  
let options = {
  namespace: 'hiPrint-',
  name: 'ls',
  storage: 'local',
};

const app = createApp(App)

// 注册所有图标  
Object.keys(Icons).forEach(key => {  
  app.component(key, Icons[key]);  
});  

app.use(constantRoutes)
app.use(ElementPlus, {
    locale: zhCn,
})
app.config.productionTip = false
app.use(Storage, options);
app.use(Antd);

//取消打印机的socket自动连接
// app.use(hiPrintPlugin);
app.use(hiPrintPlugin,'$hiprint', false);
hiPrintPlugin.disAutoConnect();

app.use(print)
app.use(store)
app.mount('#app')
app.component('Document', Document)
app.component('IconMenu', IconMenu)
app.component('User', User)
app.component('Setting', Setting)
app.component('UserFilled', UserFilled)
app.component('CreditCard', CreditCard)
app.component('Printer', Printer)
app.component('Box', Box)
app.component('Timer', Timer)
app.component('ShoppingTrolley', ShoppingTrolley)
